package com.frx.leetcode.packageone;

import java.util.TreeSet;

/**
 * @author ：frx
 * @date ：Created in 2019/3/4 21:41
 * @description：  804题  唯一莫斯密码词
 * @modified By：
 * @version: ToDO
 */
public class MorseUnique {

    public static void main(String[] args){

        String [] words = {"gin", "zen", "gig", "msg"};
        System.out.println(uniqueMorseRepresentations(words));

    }

    public static int uniqueMorseRepresentations(String[] words) {
        String[] codes ={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.",
                "---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};

        TreeSet<String> treeSet = new TreeSet<>();
        for (String word : words){
            StringBuilder res = new StringBuilder();

            for (int i = 0; i<word.length();i++){
                res.append(codes[word.charAt(i)-'a']);
            }
            treeSet.add(res.toString());
        }

        return treeSet.size();
    }
}
